package com.turbo.cloud.gateway.utils;

import org.springframework.util.AntPathMatcher;

/**
 * 访问路径工具类
 *
 * @author zhangluning
 */
public class PathUtil {

    /**
     * 静态资源
     */
    private static final String[] AUTH_STATIC_URLS = {"/", "/*.html", "/favicon.ico", "/*/*.html", "/*/*.css", "/*/*.js"};
    /**
     * 接口资源
     */
    private static final String[] AUTH_API_URLS = {"/**/oauth/**",  "/**/admin/**", "/**/interface/**"};
    /**
     * 外放类型的接口
     */
    private static final AntPathMatcher MATCHER = new AntPathMatcher();
    /**
     * 外放类型的接口
     */
    private static final String INTERFACE_MATCH = "/**/interface/**";

    /**
     * 是否包含Interface段接口
     *
     * @param path 请求地址
     */
    public static boolean isInterface(String path) {
        return MATCHER.match(INTERFACE_MATCH, path);
    }

    /**
     * 是否属于外放接口
     *
     * @param path 请求地址
     */
    public static boolean isOpenApi(String path) {
        for (String asu : AUTH_STATIC_URLS) {
            if (MATCHER.match(asu, path)) {
                return true;
            }
        }

        for (String aau : AUTH_API_URLS) {
            if (MATCHER.match(aau, path)) {
                return true;
            }
        }
        return false;
    }

}
